package rad.framework.mda.generator.template.main.java.seam;

import java.util.*;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class TreeNode
{
  protected static String nl;
  public static synchronized TreeNode create(String lineSeparator)
  {
    nl = lineSeparator;
    TreeNode result = new TreeNode();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = "/*" + NL + " * ============================================================================" + NL + " *                   GNU Lesser General Public License" + NL + " * ============================================================================" + NL + " */" + NL + "package ";
  protected final String TEXT_3 = ".editor;" + NL;
  protected final String TEXT_4 = NL + NL + "/**" + NL + " * The implementation of a RichFaces TreeNode." + NL + " *" + NL + " * @author ";
  protected final String TEXT_5 = NL + " * @generated" + NL + " */";
  protected final String TEXT_6 = NL + "public class ";
  protected final String TEXT_7 = "TreeNode extends EntityTreeNode< ";
  protected final String TEXT_8 = " > {";
  protected final String TEXT_9 = NL + "public class ";
  protected final String TEXT_10 = "TreeNode<E extends ";
  protected final String TEXT_11 = "> extends EntityTreeNode< E > {";
  protected final String TEXT_12 = NL + "public class ";
  protected final String TEXT_13 = "TreeNode<E extends ";
  protected final String TEXT_14 = "> ";
  protected final String TEXT_15 = "< E > {";
  protected final String TEXT_16 = NL + "public ";
  protected final String TEXT_17 = "class ";
  protected final String TEXT_18 = "TreeNode ";
  protected final String TEXT_19 = "< ";
  protected final String TEXT_20 = " > {";
  protected final String TEXT_21 = NL + NL + "\t/** @generated */";
  protected final String TEXT_22 = NL + "\tpublic ";
  protected final String TEXT_23 = "TreeNode(TreeNode parent, E entity) {";
  protected final String TEXT_24 = NL + "\tpublic ";
  protected final String TEXT_25 = "TreeNode(TreeNode parent, ";
  protected final String TEXT_26 = " entity) {";
  protected final String TEXT_27 = NL + "\t\tsuper(parent, entity);" + NL + "\t}" + NL + "" + NL + "\t/** @generated */" + NL + "\tpublic String getText() {";
  protected final String TEXT_28 = "\t" + NL + "\t\treturn super.getText();";
  protected final String TEXT_29 = "\t" + NL + "\t\t// TODO change as appropriate" + NL + "\t\treturn getInstance().getId().toString();";
  protected final String TEXT_30 = NL + "\t\treturn getInstance().getName();";
  protected final String TEXT_31 = NL + "\t}";
  protected final String TEXT_32 = NL + NL + "\t/**" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * --- ";
  protected final String TEXT_33 = " Folder Methods" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * " + NL + "\t * @generated" + NL + "\t */";
  protected final String TEXT_34 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_35 = "Folder = new ";
  protected final String TEXT_36 = "FolderTreeNode<";
  protected final String TEXT_37 = ">(this, ";
  protected final String TEXT_38 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_39 = "Folder = new ";
  protected final String TEXT_40 = "FolderTreeNode(this, ";
  protected final String TEXT_41 = " " + NL + "\t\t\"";
  protected final String TEXT_42 = "_";
  protected final String TEXT_43 = "\", CardinalityType.";
  protected final String TEXT_44 = ") {" + NL + "\t\t\t\t" + NL + "\t\t/** @generated */" + NL + "\t\tprotected Collection<";
  protected final String TEXT_45 = "> getCollection() {" + NL + "\t\t\treturn getInstance().get";
  protected final String TEXT_46 = "();" + NL + "\t\t}" + NL + "\t\t/** @generated */" + NL + "\t\tprotected void initNewInstance(";
  protected final String TEXT_47 = " newInstance) {" + NL + "\t\t\tnewInstance.set";
  protected final String TEXT_48 = "(getInstance());" + NL + "\t\t}" + NL + "\t};";
  protected final String TEXT_49 = " ";
  protected final String TEXT_50 = NL + NL + "\t/**" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * --- ";
  protected final String TEXT_51 = " Folder Methods" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * " + NL + "\t * @generated" + NL + "\t */";
  protected final String TEXT_52 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_53 = "Folder = new ";
  protected final String TEXT_54 = "FolderTreeNode<";
  protected final String TEXT_55 = ">(this, ";
  protected final String TEXT_56 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_57 = "Folder = new ";
  protected final String TEXT_58 = "FolderTreeNode(this, ";
  protected final String TEXT_59 = " " + NL + "\t\t\"";
  protected final String TEXT_60 = "_";
  protected final String TEXT_61 = "\", CardinalityType.M2M){" + NL + "\t\t" + NL + "\t\t/** @generated */" + NL + "\t\tprotected Collection<";
  protected final String TEXT_62 = "> getCollection() {" + NL + "\t\t\treturn getInstance().get";
  protected final String TEXT_63 = "();" + NL + "\t\t}" + NL + "\t};";
  protected final String TEXT_64 = " ";
  protected final String TEXT_65 = NL + NL + "\t/**" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * --- ";
  protected final String TEXT_66 = " Folder Methods" + NL + "\t * ------------------------------------------------------------------------" + NL + "\t * " + NL + "\t * @generated" + NL + "\t */";
  protected final String TEXT_67 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_68 = "Folder = new ";
  protected final String TEXT_69 = "FolderTreeNode<";
  protected final String TEXT_70 = ">(this, ";
  protected final String TEXT_71 = NL + "\tprotected FolderTreeNode<?> ";
  protected final String TEXT_72 = "Folder = new ";
  protected final String TEXT_73 = "FolderTreeNode(this, ";
  protected final String TEXT_74 = " " + NL + "\t\t\"";
  protected final String TEXT_75 = "_";
  protected final String TEXT_76 = "\", CardinalityType.O2O) {" + NL + "\t\t\t\t" + NL + "\t\t/** @generated */" + NL + "\t\tpublic ";
  protected final String TEXT_77 = " getOneToOne() {" + NL + "\t\t\treturn getInstance().get";
  protected final String TEXT_78 = "();" + NL + "\t\t}" + NL + "\t\t/** @generated */" + NL + "\t\tprotected void initNewInstance(";
  protected final String TEXT_79 = " newInstance) {" + NL + "\t\t\tnewInstance.set";
  protected final String TEXT_80 = "(getInstance());" + NL + "\t\t}" + NL + "\t};";
  protected final String TEXT_81 = " ";
  protected final String TEXT_82 = " " + NL + "" + NL + "\t// ------------------------------------------------------------------------" + NL + "\t// --- Folder Class" + NL + "\t// ------------------------------------------------------------------------" + NL + "\t" + NL + "\t/** @generated */";
  protected final String TEXT_83 = NL + "\tpublic static class ";
  protected final String TEXT_84 = "FolderTreeNode extends FolderTreeNode< ";
  protected final String TEXT_85 = " > {";
  protected final String TEXT_86 = NL + "\tpublic static abstract class ";
  protected final String TEXT_87 = "FolderTreeNode<E extends ";
  protected final String TEXT_88 = "> extends FolderTreeNode< E > {";
  protected final String TEXT_89 = NL + "\tpublic static abstract class ";
  protected final String TEXT_90 = "FolderTreeNode<E extends ";
  protected final String TEXT_91 = "> ";
  protected final String TEXT_92 = "< E > {";
  protected final String TEXT_93 = NL + "\tpublic static ";
  protected final String TEXT_94 = "class ";
  protected final String TEXT_95 = "FolderTreeNode ";
  protected final String TEXT_96 = "< ";
  protected final String TEXT_97 = " > {";
  protected final String TEXT_98 = NL + NL + "\t\t/** @generated */" + NL + "\t\tpublic ";
  protected final String TEXT_99 = "FolderTreeNode(TreeNode parent, String text, CardinalityType type) {" + NL + "\t\t\tsuper(parent, text, type);" + NL + "\t\t}" + NL + "" + NL + "\t\t/** @generated */" + NL + "\t\tpublic EntityTreeNode addChild(";
  protected final String TEXT_100 = " newInstance) {" + NL + "\t\t\treturn new ";
  protected final String TEXT_101 = "TreeNode(this, newInstance);" + NL + "\t\t}" + NL + "" + NL + "\t\t/** @generated */" + NL + "\t\tpublic void removeChild2(";
  protected final String TEXT_102 = " instance) {" + NL + "\t\t\tremoveChild(instance.getId());" + NL + "\t\t}" + NL + "\t}" + NL + "}";
  protected final String TEXT_103 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    org.eclipse.uml2.uml.Class uml2Class = (org.eclipse.uml2.uml.Class) argument;org.eclipse.uml2.uml.Package uml2Package = uml2Class.getPackage();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_3);
    ImportManager importManager = ImportHelper.makeImportManager("");
    ImportHelper.addImport(uml2Class);
    importManager.addImport("rad.framework.richfaces.EntityTreeNode");
    importManager.addImport("rad.framework.richfaces.FolderTreeNode");
    importManager.addImport("org.richfaces.model.TreeNode");
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_4);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_5);
    if (!ClassHelper.hasSubclasses(uml2Class) && !ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_6);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_8);
    } else if (ClassHelper.hasSubclasses(uml2Class) && !ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_9);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_10);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_11);
    } else if (ClassHelper.hasSubclasses(uml2Class)) {
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_13);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_14);
    stringBuffer.append(ClassHelper.getExtends(uml2Class, "TreeNode"));
    stringBuffer.append(TEXT_15);
    } else {
    stringBuffer.append(TEXT_16);
    stringBuffer.append(ClassHelper.getAbstract(uml2Class));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_18);
    stringBuffer.append(ClassHelper.getExtends(uml2Class, "TreeNode"));
    stringBuffer.append(TEXT_19);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_20);
    }
    stringBuffer.append(TEXT_21);
    if (ClassHelper.hasSubclasses(uml2Class)) {
    stringBuffer.append(TEXT_22);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_23);
    } else {
    stringBuffer.append(TEXT_24);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_25);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_26);
    }
    stringBuffer.append(TEXT_27);
    if (ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_28);
    } else {
    if (!ClassHelper.hasNameProperty(uml2Class)) {
    stringBuffer.append(TEXT_29);
    } else {
    stringBuffer.append(TEXT_30);
    }
    }
    stringBuffer.append(TEXT_31);
    if (ClassHelper.hasChildren(uml2Class)) {
    for (Iterator<Property> i=ClassHelper.getOwnedOneToManyProperties(uml2Class); i.hasNext();) { Property property = i.next();
    importManager.addImport("rad.framework.richfaces.FolderTreeNode");
    importManager.addImport("java.util.Collection");
    importManager.addImport("rad.framework.richfaces.FolderTreeNode.CardinalityType");
    importManager.addImport(NameHelper.getQualifiedName(property.getType().getPackage())+ ".editor." + property.getType().getName() + "TreeNode" + "." + property.getType().getName() + "FolderTreeNode");
    stringBuffer.append(TEXT_32);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_33);
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType())) {
    stringBuffer.append(TEXT_34);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_35);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_36);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_37);
    } else {
    stringBuffer.append(TEXT_38);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_39);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_40);
    }
    stringBuffer.append(TEXT_41);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_42);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_43);
    stringBuffer.append( ClassHelper.isShared(property) ? "O2MS" : "O2M");
    stringBuffer.append(TEXT_44);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_45);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_46);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_47);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_48);
    }
    stringBuffer.append(TEXT_49);
    for (Iterator<Property> i=ClassHelper.getOwnedManyToManyProperties(uml2Class); i.hasNext();) { Property property = i.next();
    importManager.addImport("rad.framework.richfaces.FolderTreeNode");
    importManager.addImport("java.util.Collection");
    importManager.addImport("rad.framework.richfaces.FolderTreeNode.CardinalityType");
    importManager.addImport(NameHelper.getQualifiedName(property.getType().getPackage())+ ".editor." + property.getType().getName() + "TreeNode" + "." + property.getType().getName() + "FolderTreeNode");
    stringBuffer.append(TEXT_50);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_51);
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType())) {
    stringBuffer.append(TEXT_52);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_53);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_54);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_55);
    } else {
    stringBuffer.append(TEXT_56);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_57);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_58);
    }
    stringBuffer.append(TEXT_59);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_60);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_61);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_62);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_63);
    }
    stringBuffer.append(TEXT_64);
    for (Iterator<Property> i=ClassHelper.getOwnedOneToOneProperties(uml2Class); i.hasNext();) { Property property = i.next();
    if (ClassHelper.isSource(property)) {
    importManager.addImport("rad.framework.richfaces.FolderTreeNode");
    importManager.addImport("rad.framework.richfaces.FolderTreeNode.CardinalityType");
    importManager.addImport(NameHelper.getQualifiedName(property.getType().getPackage())+ ".editor." + property.getType().getName() + "TreeNode" + "." + property.getType().getName() + "FolderTreeNode");
    stringBuffer.append(TEXT_65);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_66);
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType())) {
    stringBuffer.append(TEXT_67);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_68);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_69);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_70);
    } else {
    stringBuffer.append(TEXT_71);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_72);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_73);
    }
    stringBuffer.append(TEXT_74);
    stringBuffer.append(uml2Class.getName());
    stringBuffer.append(TEXT_75);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_76);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_77);
    stringBuffer.append(NameHelper.getCapName(property));
    stringBuffer.append(TEXT_78);
    stringBuffer.append(NameHelper.getCapName(property.getType()));
    stringBuffer.append(TEXT_79);
    stringBuffer.append(ClassHelper.getAccessorName(property.getOpposite()));
    stringBuffer.append(TEXT_80);
    }}
    stringBuffer.append(TEXT_81);
    }
    stringBuffer.append(TEXT_82);
    if (!ClassHelper.hasSubclasses(uml2Class) && !ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_83);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_84);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_85);
    } else if (ClassHelper.hasSubclasses(uml2Class) && !ClassHelper.hasSuperClass(uml2Class)) {
    stringBuffer.append(TEXT_86);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_87);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_88);
    } else if (ClassHelper.hasSubclasses(uml2Class)) {
    stringBuffer.append(TEXT_89);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_90);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_91);
    stringBuffer.append(ClassHelper.getExtends(uml2Class, "FolderTreeNode"));
    stringBuffer.append(TEXT_92);
    } else {
    stringBuffer.append(TEXT_93);
    stringBuffer.append(ClassHelper.getAbstract(uml2Class));
    stringBuffer.append(TEXT_94);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_95);
    stringBuffer.append(ClassHelper.getExtends(uml2Class, "FolderTreeNode"));
    stringBuffer.append(TEXT_96);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_97);
    }
    stringBuffer.append(TEXT_98);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_99);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_100);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_101);
    stringBuffer.append(NameHelper.getCapName(uml2Class));
    stringBuffer.append(TEXT_102);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_103);
    return stringBuffer.toString();
  }
}
